package com.siemens.industrial.app;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created by qupen on 2016/9/22.
 */
public class HttpHelper {
    public static String doGet(String serviceAddress) {
        StringBuffer buffer = new StringBuffer();
        try {
            URL url = new URL(serviceAddress);
            HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();

            if (httpURLConnection.getResponseCode() == 200) {
                BufferedReader in = new BufferedReader(new InputStreamReader(
                        httpURLConnection.getInputStream()));
                String line;
                while ((line = in.readLine()) != null) {
                    buffer.append(line);
                }

                return buffer.toString();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
}
